﻿using AuroraPlatform.Tools;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AuroraPlatform.ViewModel
{
    public class SignModel : NotifyingObject
    {
        private string _name;

        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                this.RaisePropertyChanged("Name");
            }
        }

        private int _isMain;

        public int IsMain
        {
            get { return _isMain; }
            set
            {
                _isMain = value;
                this.RaisePropertyChanged("IsMain");
            }
        }
    }

    public class LightingType
    {
        public string Name { get; set; }
        public string PictureUri { get; set; }
        public int UsePlace { get; set; }
        public int Class { get; set; }
        public int Setup { get; set; }
        public string Alias { get; set; }
    }

    public class LightingClassModel
    {
        public string ProdLabel { get; set; }
        public string PicFacade { get; set; }
        public string ProdSeries { get; set; }
        public int AdpClass { get; set; }
    }

    public class LightingListModel : NotifyingObject
    {
        private Visibility _visibility = Visibility.Collapsed;

        public Visibility Visibility
        {
            get { return _visibility; }
            set
            {
                _visibility = value;
                this.RaisePropertyChanged("Visibility");
            }
        }

        private bool _checked;

        public bool IsChecked
        {
            get { return _checked; }
            set
            {
                _checked = value;
                this.RaisePropertyChanged("IsChecked");
            }
        }

        public string PicFacade { get; set; }
        public string ProdSeries { get; set; }
        public int ProdClass { get; set; }
        public string ProdLabel { get; set; }
        public string ProdVersion { get; set; }
        public string PhySize { get; set; }
        public int AdpClass { get; set; }
        public int EleLgtPower { get; set; }
        public string AdpColor { get; set; }
        public int AdpCri { get; set; }
        public string OptAngle { get; set; }
        public double BusMarket { get; set; }
        public string ID { get; set; }
    }

    public class LightingPrimaryModel
    {
        public string ID { get; set; }
        public string ProdSeries { get; set; }
        public int ProdClass { get; set; }
        public int ProdPlace { get; set; }
        public string ProdVersion { get; set; }
        public string ProdLabel { get; set; }
        public string PhyColor { get; set; }
        public string PhySize { get; set; }
        public string PhyDefend { get; set; }
        public int PhyImpact { get; set; }
        public int AdpClass { get; set; }
        public string AdpColor { get; set; }
        public int EleLgtPower { get; set; }
        public int AdpCri { get; set; }
        public string OptAngle { get; set; }
        public int ProjSetup { get; set; }
        public double BusMarket { get; set; }
        public string PicFacade { get; set; }
        public string PicSize { get; set; }
        public string PicGrading { get; set; }

        public string PicLive { get; set; }
    }

    public class LightingModel : NotifyingObject, IDataErrorInfo
    {
        private Dictionary<string, string> _validateErros = new Dictionary<string, string>();
        private static Dictionary<string, string> _columnNames;
        public string ID { get; set; }

        private bool _isEnabled = true;
        public bool IsEnabled
        {
            get
            {
                return _isEnabled;
            }
            set
            {
                _isEnabled = value;
                this.RaisePropertyChanged("IsEnabled");
            }
        }

        private int _prodClass;
        public int ProdClass
        {
            get
            {
                return _prodClass;
            }
            set
            {
                _prodClass = value;
                this.RaisePropertyChanged("ProdClass");
            }
        }

        private int _prodPlace;

        /// <summary>
        /// 主要信息：使用场所
        /// </summary>
        public int ProdPlace
        {
            get
            {
                return _prodPlace;
            }
            set
            {
                _prodPlace = value;
                this.RaisePropertyChanged("ProdPlace");
            }
        }

        private int _prodOrgin;
        public int ProdOrgin
        {
            get
            {
                return _prodOrgin;
            }
            set
            {
                _prodOrgin = value;
                this.RaisePropertyChanged("ProdOrgin");
            }
        }

        private string _prodSeries;
        public string ProdSeries
        {
            get
            {
                return _prodSeries;
            }
            set
            {
                _prodSeries = value;
                this.RaisePropertyChanged("ProdSeries");
            }
        }
        private string _prodVersion;
        public string ProdVersion
        {
            get
            {
                return _prodVersion;
            }
            set
            {
                _prodVersion = value;
                this.RaisePropertyChanged("ProdVersion");
            }
        }
        private string _prodLabel;
        public string ProdLabel
        {
            get
            {
                return _prodLabel;
            }
            set
            {
                _prodLabel = value;
                this.RaisePropertyChanged("ProdLabel");
            }
        }

        private int _phyImpact;
        public int PhyImpact
        {
            get
            {
                return _phyImpact;
            }
            set
            {
                _phyImpact = value;
                this.RaisePropertyChanged("PhyImpact");
            }
        }

        static LightingModel()
        {
            _columnNames = new Dictionary<string, string>();
            _columnNames["PhyWeight"] = "产品重量";
            _columnNames["AdpOutput"] = "光输出";
            _columnNames["AdpCri"] = "显色性";
            _columnNames["ElePower"] = "电器功耗";
            _columnNames["EleAllPower"] = "整灯功耗";
            _columnNames["EleLgtPower"] = "光源功率";
            _columnNames["OptEff"] = "灯具效率";
            _columnNames["BusMarket"] = "市场参考价";
            _columnNames["BusIn"] = "参考进价";
            _columnNames["BusOut"] = "参考售价";
        }

        private string _phyWeight;
        public string PhyWeight
        {
            get
            {
                return _phyWeight;
            }
            set
            {
                string key = "PhyWeight";

                bool hasError = false;
                if (!string.IsNullOrEmpty(value))
                {
                    double dValue;
                    if (!double.TryParse(value, out dValue))
                    {
                        _validateErros[key] = "请输入数值。";
                        hasError = true;
                    }
                }


                if (!hasError)
                {
                    if (_validateErros.ContainsKey(key))
                    {
                        _validateErros.Remove(key);
                    }
                }

                if (_phyWeight != value)
                {
                    _phyWeight = value;
                    this.RaisePropertyChanged(key);
                }
            }
        }

        public string ErrorColumns
        {
            get
            {
                if (_validateErros.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("【");
                    foreach (string key in _validateErros.Keys)
                    {
                        sb.AppendFormat("{0}，", _columnNames[key]);
                    }
                    sb.Remove(sb.Length - 1, 1);
                    sb.Append("】");
                    return sb.ToString();
                }
                return null;
            }
        }

        public string PicFolder { get; set; }

        private string _phyColor;
        public string PhyColor
        {
            get
            {
                return _phyColor;
            }
            set
            {
                _phyColor = value;
                this.RaisePropertyChanged("PhyColor");
            }
        }

        private string _phySize;
        public string PhySize
        {
            get
            {
                return _phySize;
            }
            set
            {
                _phySize = value;
                this.RaisePropertyChanged("PhySize");
            }
        }

        private string _phyDefend;
        public string PhyDefend
        {
            get
            {
                return _phyDefend;
            }
            set
            {
                _phyDefend = value;
                this.RaisePropertyChanged("PhyDefend");
            }
        }

        private string _phyMaterial;
        public string PhyMaterial
        {
            get
            {
                return _phyMaterial;
            }
            set
            {
                _phyMaterial = value;
                this.RaisePropertyChanged("PhyMaterial");
            }
        }

        private string _adpOutput;
        public string AdpOutput
        {
            get
            {
                return _adpOutput;
            }
            set
            {
                string key = "AdpOutput";

                bool hasError = false;
                if (!string.IsNullOrEmpty(value))
                {
                    int dValue;
                    if (!int.TryParse(value, out dValue))
                    {
                        _validateErros[key] = "请输入整数。";
                        hasError = true;
                    }
                }


                if (!hasError)
                {
                    if (_validateErros.ContainsKey(key))
                    {
                        _validateErros.Remove(key);
                    }
                }

                if (_adpOutput != value)
                {
                    _adpOutput = value;
                    this.RaisePropertyChanged(key);
                }
            }
        }
        private int _adpClass;
        public int AdpClass
        {
            get
            {
                return _adpClass;
            }
            set
            {
                _adpClass = value;
                this.RaisePropertyChanged("AdpClass");
            }
        }

        private string _adpCri;
        public string AdpCri
        {
            get
            {
                return _adpCri;
            }
            set
            {
                string key = "AdpCri";

                bool hasError = false;
                if (!string.IsNullOrEmpty(value))
                {
                    int dValue;
                    if (!int.TryParse(value, out dValue))
                    {
                        _validateErros[key] = "请输入整数。";
                        hasError = true;
                    }
                }


                if (!hasError)
                {
                    if (_validateErros.ContainsKey(key))
                    {
                        _validateErros.Remove(key);
                    }
                }

                if (_adpCri != value)
                {
                    _adpCri = value;
                    this.RaisePropertyChanged(key);
                }
            }
        }

        private string _adpVersion;
        public string AdpVersion
        {
            get
            {
                return _adpVersion;
            }
            set
            {
                _adpVersion = value;
                this.RaisePropertyChanged("AdpVersion");
            }
        }

        private string _adpPins;
        public string AdpPins
        {
            get
            {
                return _adpPins;
            }
            set
            {
                _adpPins = value;
                this.RaisePropertyChanged("AdpPins");
            }
        }

        private string _adpColor;
        public string AdpColor
        {
            get
            {
                return _adpColor;
            }
            set
            {
                _adpColor = value;
                this.RaisePropertyChanged("AdpColor");
            }
        }



        private string _elePower;
        public string ElePower
        {
            get
            {
                return _elePower;
            }
            set
            {
                string key = "ElePower";

                bool hasError = false;
                if (!string.IsNullOrEmpty(value))
                {
                    int dValue;
                    if (!int.TryParse(value, out dValue))
                    {
                        _validateErros[key] = "请输入整数。";
                        hasError = true;
                    }
                }


                if (!hasError)
                {
                    if (_validateErros.ContainsKey(key))
                    {
                        _validateErros.Remove(key);
                    }
                }

                if (_elePower != value)
                {
                    _elePower = value;
                    this.RaisePropertyChanged(key);
                }
            }
        }



        private string _eleAllPower;
        public string EleAllPower
        {
            get
            {
                return _eleAllPower;
            }
            set
            {
                string key = "EleAllPower";

                bool hasError = false;
                if (!string.IsNullOrEmpty(value))
                {
                    int dValue;
                    if (!int.TryParse(value, out dValue))
                    {
                        _validateErros[key] = "请输入整数。";
                        hasError = true;
                    }
                }


                if (!hasError)
                {
                    if (_validateErros.ContainsKey(key))
                    {
                        _validateErros.Remove(key);
                    }
                }

                if (_eleAllPower != value)
                {
                    _eleAllPower = value;
                    this.RaisePropertyChanged(key);
                }
            }
        }

        private int _eleCtlType;
        public int EleCtlType
        {
            get
            {
                return _eleCtlType;
            }
            set
            {
                _eleCtlType = value;
                this.RaisePropertyChanged("EleCtlType");
            }
        }

        private string _eleLgtPower;
        public string EleLgtPower
        {
            get
            {
                return _eleLgtPower;
            }
            set
            {

                string key = "EleLgtPower";

                bool hasError = false;
                if (!string.IsNullOrEmpty(value))
                {
                    int dValue;
                    if (!int.TryParse(value, out dValue))
                    {
                        _validateErros[key] = "请输入整数。";
                        hasError = true;
                    }
                }


                if (!hasError)
                {
                    if (_validateErros.ContainsKey(key))
                    {
                        _validateErros.Remove(key);
                    }
                }

                if (_eleLgtPower != value)
                {
                    _eleLgtPower = value;
                    this.RaisePropertyChanged(key);
                }
            }
        }

        private int _eleVoltage;
        public int EleVoltage
        {
            get
            {
                return _eleVoltage;
            }
            set
            {
                _eleVoltage = value;
                this.RaisePropertyChanged("EleVoltage");
            }
        }

        private string _eleShock;
        public string EleShock
        {
            get
            {
                return _eleShock;
            }
            set
            {
                _eleShock = value;
                this.RaisePropertyChanged("EleShock");
            }
        }

        private string _eleType;
        public string EleType
        {
            get
            {
                return _eleType;
            }
            set
            {
                _eleType = value;
                this.RaisePropertyChanged("EleType");
            }
        }

        private int _optExplain;
        public int OptExplain
        {
            get
            {
                return _optExplain;
            }
            set
            {
                _optExplain = value;
                this.RaisePropertyChanged("OptExplain");
            }
        }

        private string _optEff;
        public string OptEff
        {
            get
            {
                return _optEff;
            }
            set
            {

                string key = "OptEff";

                bool hasError = false;
                if (!string.IsNullOrEmpty(value))
                {
                    double dValue;
                    if (!double.TryParse(value, out dValue))
                    {
                        _validateErros[key] = "请输入数值。";
                        hasError = true;
                    }
                }


                if (!hasError)
                {
                    if (_validateErros.ContainsKey(key))
                    {
                        _validateErros.Remove(key);
                    }
                }

                if (_optEff != value)
                {
                    _optEff = value;
                    this.RaisePropertyChanged(key);
                }
            }
        }

        private string _optAngle;
        public string OptAngle
        {
            get
            {
                return _optAngle;
            }
            set
            {
                _optAngle = value;
                this.RaisePropertyChanged("OptAngle");
            }
        }

        private int _projSetup;
        public int ProjSetup
        {
            get
            {
                return _projSetup;
            }
            set
            {
                _projSetup = value;
                this.RaisePropertyChanged("ProjSetup");
            }
        }
        private string _projParts;
        public string ProjParts
        {
            get
            {
                return _projParts;
            }
            set
            {
                _projParts = value;
                this.RaisePropertyChanged("ProjParts");
            }
        }

        private string _projSize;
        public string ProjSize
        {
            get
            {
                return _projSize;
            }
            set
            {
                _projSize = value;
                this.RaisePropertyChanged("ProjSize");
            }
        }

        private string _projReport;
        public string ProjReport
        {
            get
            {
                return _projReport;
            }
            set
            {
                _projReport = value;
                this.RaisePropertyChanged("ProjReport");
            }
        }

        private string _projBaikup;
        public string ProjBaikup
        {
            get
            {
                return _projBaikup;
            }
            set
            {
                _projBaikup = value;
                this.RaisePropertyChanged("ProjBaikup");
            }
        }
        private string _busMarket;
        public string BusMarket
        {
            get
            {
                return _busMarket;
            }
            set
            {


                string key = "BusMarket";

                bool hasError = false;
                if (!string.IsNullOrEmpty(value))
                {
                    double dValue;
                    if (!double.TryParse(value, out dValue))
                    {
                        _validateErros[key] = "请输入数值。";
                        hasError = true;
                    }
                }


                if (!hasError)
                {
                    if (_validateErros.ContainsKey(key))
                    {
                        _validateErros.Remove(key);
                    }
                }

                if (_busMarket != value)
                {
                    _busMarket = value;
                    this.RaisePropertyChanged(key);
                }
            }
        }

        private string _busIn;
        public string BusIn
        {
            get
            {
                return _busIn;
            }
            set
            {
                string key = "BusIn";

                bool hasError = false;
                if (!string.IsNullOrEmpty(value))
                {
                    double dValue;
                    if (!double.TryParse(value, out dValue))
                    {
                        _validateErros[key] = "请输入数值。";
                        hasError = true;
                    }
                }


                if (!hasError)
                {
                    if (_validateErros.ContainsKey(key))
                    {
                        _validateErros.Remove(key);
                    }
                }

                if (_busIn != value)
                {
                    _busIn = value;
                    this.RaisePropertyChanged(key);
                }
            }
        }

        private string _busOut;
        public string BusOut
        {
            get
            {
                return _busOut;
            }
            set
            {
                string key = "BusOut";
                bool hasError = false;
                if (!string.IsNullOrEmpty(value))
                {
                    double dValue;
                    if (!double.TryParse(value, out dValue))
                    {
                        _validateErros[key] = "请输入数值。";
                        hasError = true;
                    }
                }


                if (!hasError)
                {
                    if (_validateErros.ContainsKey(key))
                    {
                        _validateErros.Remove(key);
                    }
                }

                if (_busOut != value)
                {
                    _busOut = value;
                    this.RaisePropertyChanged(key);
                }
            }
        }

        private string _busExpires;
        public string BusExpires
        {
            get
            {
                return _busExpires;
            }
            set
            {
                _busExpires = value;
                this.RaisePropertyChanged("BusExpires");
            }
        }

        public string PicFacade { get; set; }
        public string PicSize { get; set; }
        public string PicGrading { get; set; }
        public string PicLive { get; set; }

        public byte[] UploadFacade { get; set; }
        public byte[] UploadGrading { get; set; }
        public byte[] UploadSize { get; set; }
        public byte[] UploadLive { get; set; }

        #region IDataErrorInfo
        public string Error
        {
            get { return string.Empty; }
        }

        public string this[string columnName]
        {
            get { return _validateErros.ContainsKey(columnName) ? _validateErros[columnName] : null; }
        }
        #endregion
    }

    public class PictureConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return new BitmapImage(new Uri(value.ToString(), UriKind.RelativeOrAbsolute));
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
